package com.yunquan.ohana.ui.weather

import androidx.databinding.ObservableField
import com.yunquan.ohana.base.ui.ItemViewModel
import com.yunquan.ohana.entity.Daily
import com.yunquan.ohana.entity.Hourly
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.OffsetDateTime
import java.time.format.DateTimeFormatter

class WeatherDayItemViewModel(viewModel: WeatherViewModel) : ItemViewModel<WeatherViewModel>(viewModel) {

    var data: Daily? = null
    val week = ObservableField<String>()
    val tempMax = ObservableField<String>()
    val tempMin = ObservableField<String>()
    val icon = ObservableField<Int>()
    val showPop = ObservableField<Boolean>(false)
    val pop = ObservableField<String>()

    val weekFormat: DateTimeFormatter = DateTimeFormatter.ofPattern("EEE")

    constructor(viewModel: WeatherViewModel, data: Daily) : this(viewModel) {
        this.data = data
        data.fxDate?.let {
            LocalDate.parse(it).apply {
                if (LocalDateTime.now().dayOfWeek.value == this.dayOfWeek.value) {
                    week.set("Today")
                } else {
                    week.set(weekFormat.format(this))
                }
            }
        }
        this.tempMax.set("${data.tempMax}℃")
        this.tempMin.set("/${data.tempMin}℃")
        this.icon.set(data.getWeatherRes())
        this.pop.set("${data.humidity}%")

    }
}